﻿Public Class ADDPROVIDER
    Public Sub New(ByVal usmk As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        publicUsmk = usmk
    End Sub

    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_MASPROVIDER As New PROVIDERSCLASS
    Dim publicUsmk As Integer

    Public Sub filterPrename(sex As String)
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(a.PRENAME AS CHAR(8)) AS PRENAME, a.FTPRENAME, b.SEXDESC FROM masprename a LEFT JOIN massex b ON a.sex = b.SEX WHERE a.STATUS = '1' AND a.sex = '" & sex & "'"
        s = New FILTERCLASS(txtPrename, sql, "id,คำนำหน้าชื่อ,เพศ", "50,160,50", "1,1,1", "1,1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Public Sub filterSex()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(sex AS CHAR(8)) as sex, sexdesc FROM massex WHERE `status` = '1'"
        s = New FILTERCLASS(txtSex, sql, "id เพศ,เพศ", "50,120", "1,1", "1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Public Sub filterProtype()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(protype AS CHAR(8)) as protype, proname FROM masprotype WHERE `status` = '1'"
        s = New FILTERCLASS(txtProtype, sql, "id,ประเภทผู้ให้บริการ", "30,120", "1,1", "1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Public Sub filterMasclinic()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(clinic AS CHAR(8)) as clinic, clinicname, cliniccode FROM masclinic WHERE `status` = '1'"
        s = New FILTERCLASS(txtClinic, sql, "id,ชื่อคลินิก,code", "30,120,50", "1,1,1", "1,1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Public Sub filterMasclinic2()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(clinic AS CHAR(8)) as clinic, clinicname, cliniccode FROM masclinic WHERE `status` = '1'"
        s = New FILTERCLASS(txtDcl, sql, "id,ชื่อคลินิก,code", "30,120,50", "1,1,1", "1,1,1")
        s.SetShowInDown = False
        s.SetShowBorder = True
    End Sub

    Private Sub ADDPROVIDER_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'filterPrename()
        filterSex()
        filterMasclinic()
        filterMasclinic2()
        filterProtype()

        linDcl.Visible = False
        txtDcl.Visible = False
        lblDcl.Visible = False
    End Sub

    Private Sub ckbF_doc_CheckedChanged(sender As Object, e As EventArgs) Handles ckbF_doc.CheckedChanged
        If ckbF_doc.Checked = True Then
            linDcl.Visible = True
            txtDcl.Visible = True
            lblDcl.Visible = True
        Else
            linDcl.Visible = False
            txtDcl.Visible = False
            lblDcl.Visible = False
            txtDcl.Text = Nothing
            txtDcl.Tag = Nothing
        End If
    End Sub


    '--------auto prename by gender----------
    Private Sub txtSex_TextChanged(sender As Object, e As EventArgs) Handles txtSex.TextChanged
        filterPrename(Convert.ToString(txtSex.Tag))
    End Sub


    '--------check password----------
    Private Sub UMAINPASSTxt_TextChanged(sender As Object, e As EventArgs) Handles txtUserRequest.TextChanged
        If txtUserRequest.Text = txtConfirmUserRequest.Text Then
            passwordMatch.Visible = False
            btnAddProvider.Enabled = True
        Else
            passwordMatch.Visible = True
            btnAddProvider.Enabled = False
        End If
    End Sub

    Private Sub CONFIRMPASSTxt_TextChanged(sender As Object, e As EventArgs) Handles txtConfirmUserRequest.TextChanged
        If txtUserRequest.Text = txtConfirmUserRequest.Text Then
            passwordMatch.Visible = False
            btnAddProvider.Enabled = True
        Else
            passwordMatch.Visible = True
            btnAddProvider.Enabled = False
        End If
    End Sub

    Private Sub addProvider_Click_1(sender As Object, e As EventArgs) Handles btnAddProvider.Click
        'If main.PROVIDERPOLICIES.checklogin_user_ = True Then
        'If PROVIDER_MASPROVIDER.PADD_ = True Then
        If Convert.ToString(txtPrename.Tag) IsNot Nothing And txtName.Text.ToString.Length > 0 And txtLname.Text.Length.ToString > 0 And txtNname.Text.Length.ToString > 0 And txtUserRequest.Text.Length.ToString > 0 And txtConfirmUserRequest.Text.Length.ToString > 0 Then
            Dim objInsertData As New PROVIDERCLASS
            objInsertData.CID_ = txtCID.Text
            objInsertData.REGISTERNO_ = txtRegisterNo.Text
            objInsertData.PROVIDER_ = txtProvider.Text
            objInsertData.PRENAME_ = txtPrename.Tag
            objInsertData.NAME_ = txtName.Text
            objInsertData.LNAME_ = txtLname.Text
            objInsertData.NNAME_ = txtNname.Text
            objInsertData.NAME_EN_ = txtNameEn.Text

            If Convert.ToString(txtSex.Tag) IsNot Nothing Then
                objInsertData.SEX_ = txtSex.Tag
            Else
                objInsertData.SEX_ = 0
            End If

            If Convert.ToString(txtClinic.Tag) IsNot Nothing Then
                objInsertData.CLINIC_ = txtClinic.Tag
            Else
                objInsertData.CLINIC_ = 0
            End If

            If Convert.ToString(txtDcl.Tag) IsNot Nothing Then
                objInsertData.DCL_ = txtDcl.Tag
            Else
                objInsertData.DCL_ = 0
            End If

            If Convert.ToString(txtProtype.Tag) IsNot Nothing Then
                objInsertData.PROTYPE_ = txtProtype.Tag
            Else
                objInsertData.DCL_ = 0
            End If


            objInsertData.BDATE_ = DateAdd(DateInterval.Year, -543, dtpBdate.Value).ToString("yyyy/MM/dd")
            objInsertData.APPDATE_ = DateAdd(DateInterval.Year, -543, dtpAppdate.Value).ToString("yyyy/MM/dd")
            objInsertData.STARTDATE_ = DateAdd(DateInterval.Year, -543, dtpStdate.Value).ToString("yyyy/MM/dd")
            objInsertData.LEDATE_ = DateAdd(DateInterval.Year, -543, dtpLedate.Value).ToString("yyyy/MM/dd")
            objInsertData.F_CASH_ = ckbF_cash.Checked
            objInsertData.F_DR_ = ckbF_doc.Checked
            objInsertData.F_LOGIN_ = ckbF_cash.Checked
            objInsertData.USREQ_ = txtUserRequest.Text
            objInsertData.USMK_ = publicUsmk
            objInsertData.providerstatus_ = ckbHospempStatus.Checked


            If objInsertData.insertproviderData() = True Then
                DialogResult = Windows.Forms.DialogResult.OK
                Me.Close()
            End If
        Else
            MsgBox("โปรดระบุข้อมูลให้ครบถ้วนก่อนทำการเพิ่มข้อมูล", MsgBoxStyle.Critical)
        End If

        'SelectDatagridprovider()

        'cleardata()
        'Else
        'MsgBox(PROVIDER_MASPROVIDER.PADDMSG_)
        'End If
        'Else
        'TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
        'main.txtUserRequest.Focus()
        'End If
    End Sub


    
End Class